﻿Public Class PanelIcon
    Inherits PictureBox
    Public mintIndex As Integer
    Public mobjIconPanel As IconPanel

    Private mobjBckgColor As Color
    Private mblnMouseEnter As Boolean

    Public ReadOnly Property Index As Integer
        Get
            Return mintIndex
        End Get
    End Property


    Public Sub New(ByVal parent As IconPanel, ByVal image As Image, ByVal index As Integer, ByVal onClickEvent As EventHandler)
        mintIndex = index
        mobjIconPanel = parent
        Me.Image = image
        Visible = True
        Location = New Point(mobjIconPanel.outlookBar.Size.Width / 2 - image.Size.Width / 2,
                             mobjIconPanel.Margin + index * mobjIconPanel.IconSpacing)
        Size = image.Size
        AddHandler Click, onClickEvent
        Tag = Me


        mobjBckgColor = mobjIconPanel.BackColor
        mblnMouseEnter = False
    End Sub

    Protected Overrides Sub OnMouseMove(ByVal args As MouseEventArgs)
        If args.X < Size.Width - 2 And args.Y < Size.Height - 2 And Not mblnMouseEnter Then
            BackColor = Color.LightCyan
            BorderStyle = Windows.Forms.BorderStyle.FixedSingle
            Location = Location - New Size(1, 1)
            mblnMouseEnter = True
        End If
        MyBase.OnMouseMove(args)
    End Sub

    Protected Overrides Sub OnMouseLeave(e As System.EventArgs)
        If mblnMouseEnter Then
            BackColor = mobjBckgColor
            BorderStyle = Windows.Forms.BorderStyle.None
            Location = Location + New Size(1, 1)
            mblnMouseEnter = False
        End If
        MyBase.OnMouseLeave(e)
    End Sub

End Class
